<template>
  <div class="infinite-container">
    <div class="not-found" v-if="depts.length === 0">
      <div>
        <p class="mt20">暂无挂号方案</p>
        <p class="mt20">
          <router-link to="/appointment/select-department">手动选择科室</router-link>
        </p>
      </div>
    </div>
  
    <div v-else>
       <mu-list class="mt10">
          <mu-sub-header>推荐科室</mu-sub-header>
      </mu-list>
      <div class="bgwhite" v-for="dept in depts" :key="dept.localDeptId">
      <mu-list >
          <mu-list-item :title="dept.deptName"  @click="goDoctorPage(dept)">
          </mu-list-item>
      </mu-list>
      </div>
      <mu-divider></mu-divider>
    </div>


  </div>
</template>
<script>
import {commonAjax, PLATFORM_PREFIX} from '../api/api'
export default {
  data () {
    return {
      depts: []
    }
  },
  mounted () {
    this.$store.commit('UPDATE_LOADING')
    commonAjax([this.$route.query.deptId], `${PLATFORM_PREFIX}.deptContrastService`, 'getDeptContrastById').then(res => {
      this.$store.commit('UPDATE_LOADING')
      if (res.data.code === 200) {
        if (res.data.body.length === 1) {
          // 只有一个科室匹配
          localStorage.dept = JSON.stringify(res.data.body[0])
          this.$router.replace('/appointment/select-doctor')
        } else {
        // 多个科室匹配
          this.depts = res.data.body
        }
      } else {
        this.$store.commit('UPDATE_TOAST', {message: res.data.msg})
      }
    }).catch(res => {
      this.$store.commit('UPDATE_LOADING')
    })
  },
  methods: {
    goDoctorPage (dept) {
      localStorage.dept = JSON.stringify(dept)
      this.$router.replace('/appointment/select-doctor')
    }
  }
}
</script>
